Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[discover] Less field list loading #147825

Merged
merged 6 commits into from
Dec 22, 2022

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Dec 20, 2022

Summary

Looking at why Discover was loading data view field lists were loading more than needed, I found more reasons than actual field list loads occurring but I think they're all deserving of improvement.

  • Discover was loading the default data view to see if there was an existing data view. We can rely on the hasData api instead.
  • We were loading a data view and then refreshing the field list. If the data view was being loaded fresh, its meant the field list was loaded twice. Field list refresh has been integrated into the dataViews api.
  • We were loading a data view, checking it if was adhoc, and tossing it if it wasn't. Now we keep the reference.

Previously on page load, discover would make 3 calls to fields_for_wildcard, now it makes two. It loads all the field with one request and it makes an additional request where it applies the current filter to find relevant fields.

Closes #147744

@mattkime mattkime changed the title less field list loading [discover] Less field list loading Dec 20, 2022
@@ -93,13 +93,6 @@ export function DiscoverMainRoute(props: Props) {
return;
}

const defaultDataView = await data.dataViews.getDefaultDataView();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality duplicates what dataViews.hasData is doing. If it doesn't work, it should be fixed.

@@ -111,7 +104,6 @@ export function DiscoverMainRoute(props: Props) {

const ipList = ip.list;
const dataViewData = resolveDataView(ip, nextSavedSearch.searchSource, toastNotifications);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refreshFields has been added to the data view loading functions - previously the data view would be loaded, triggering the first field list load, and then it would be loaded again to make sure it was fresh.

@@ -38,9 +38,6 @@ export function findDataViewById(
dataViews: DataViewListItem[],
id: string
): DataViewListItem | undefined {
if (!Array.isArray(dataViews) || !id) {
return;
}
return dataViews.find((o) => o.id === id);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this code since its enforced by type safety. Let me know if there's some reason why this shouldn't be done.

// try to fetch adhoc data view first
try {
const fetchedDataView = fetchId ? await dataViews.get(fetchId) : undefined;
fetchedDataView = fetchId ? await dataViews.get(fetchId) : undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously this code was loading a data view, checking if it was adhoc, then tossing the result. Now we hold on to it in case its the data view we wanted to load.

@@ -122,12 +120,14 @@ export async function loadDataView(
} catch (e) {}

// fetch persisted data view
const actualId = getDataViewId(fetchId, dataViewList, config.get('defaultIndex'));
return {
Copy link
Contributor Author

@mattkime mattkime Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need getDataViewId because dataViews.getDefaultDataView does the work - it provides the default data view and if it doesn't exist then it sets another default and if there aren't any data views...well, thats what the hasData check is for.

@mattkime mattkime marked this pull request as ready for review December 20, 2022 03:55
@mattkime mattkime requested a review from a team as a code owner December 20, 2022 03:55
@mattkime mattkime added v8.7.0 Feature:Discover Discover Application Feature:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) labels Dec 20, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@ninoslavmiskovic
Copy link
Contributor

@mattkime This is a great improvement. Are we able to calculate e.g how much speed improvement this gives on a large data set ?

@mattkime
Copy link
Contributor Author

@ninoslavmiskovic

Are we able to calculate e.g how much speed improvement this gives on a large data set ?

Somewhere between 50% and 33% faster, although our goal should be to load the field list without a noticeable delay.

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, thx for fixing this, could you also have a look at the data view switching behavior, there are also 3 requests that could be 2
Bildschirmfoto 2022-12-21 um 11 46 11

@mattkime mattkime requested a review from a team as a code owner December 21, 2022 19:58
@mattkime
Copy link
Contributor Author

@kertal

could you also have a look at the data view switching behavior, there are also 3 requests that could be 2

resolved!

@mattkime mattkime requested a review from kertal December 22, 2022 07:00
@ninoslavmiskovic
Copy link
Contributor

@kertal

could you also have a look at the data view switching behavior, there are also 3 requests that could be 2

resolved!

More speed 👍

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
dataViews 230 231 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 418.9KB 418.6KB -332.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dataViews 45.5KB 45.6KB +110.0B
unifiedSearch 51.7KB 51.6KB -43.0B
total +67.0B
Unknown metric groups

API count

id before after diff
data 3296 3300 +4
dataViews 1024 1032 +8
total +12

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 61 67 +6
osquery 109 115 +6
securitySolution 436 442 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 70 76 +6
osquery 110 117 +7
securitySolution 512 518 +6
total +21

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unified search changes LGTM, great improvement :)

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thx for this improvement 🙏 very appreciated!

@mattkime mattkime merged commit 4715e71 into elastic:main Dec 22, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 22, 2022
pgayvallet pushed a commit to pgayvallet/kibana that referenced this pull request Dec 22, 2022
## Summary

Looking at why Discover was loading data view field lists were loading
more than needed, I found more reasons than actual field list loads
occurring but I think they're all deserving of improvement.

- Discover was loading the default data view to see if there was an
existing data view. We can rely on the `hasData` api instead.
- We were loading a data view and then refreshing the field list. If the
data view was being loaded fresh, its meant the field list was loaded
twice. Field list refresh has been integrated into the dataViews api.
- We were loading a data view, checking it if was adhoc, and tossing it
if it wasn't. Now we keep the reference.

Previously on page load, discover would make 3 calls to
`fields_for_wildcard`, now it makes two. It loads all the field with one
request and it makes an additional request where it applies the current
filter to find relevant fields.

Closes elastic#147744
crespocarlos pushed a commit to crespocarlos/kibana that referenced this pull request Dec 23, 2022
## Summary

Looking at why Discover was loading data view field lists were loading
more than needed, I found more reasons than actual field list loads
occurring but I think they're all deserving of improvement.

- Discover was loading the default data view to see if there was an
existing data view. We can rely on the `hasData` api instead.
- We were loading a data view and then refreshing the field list. If the
data view was being loaded fresh, its meant the field list was loaded
twice. Field list refresh has been integrated into the dataViews api.
- We were loading a data view, checking it if was adhoc, and tossing it
if it wasn't. Now we keep the reference.

Previously on page load, discover would make 3 calls to
`fields_for_wildcard`, now it makes two. It loads all the field with one
request and it makes an additional request where it applies the current
filter to find relevant fields.

Closes elastic#147744
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Data Views Data Views code and UI - index patterns before 8.0 Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover] Reduce number of request for fields when switching a data view in Discover
7 participants